import CryptoJS from 'crypto-js';
import { jwtSecretMd5 } from '../config';

const encrypt = (word: string) => {
  return CryptoJS.AES.encrypt(JSON.stringify(word), jwtSecretMd5).toString();
};

const decrypt = (word: string) => {
  const bytes = CryptoJS.AES.decrypt(word, jwtSecretMd5).toString(CryptoJS.enc.Utf8);
  return JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
};

export default {
  encrypt,
  decrypt
};
